{extend name="index/index" /}
{block name="main"}
{js href="/static/index/js/jquery.min.js"}
<div class="content-page">

    <div class="content">

        <div class="page-heading">
            <h1><i class='fa fa-table'></i>广告管理</h1>
            <h3>广告列表</h3></div>

        <div class="row">

            <div class="col-md-12">
                <div class="widget">
                    <div class="widget-header transparent">
                        <h2><strong>Sortable</strong> Table</h2>

                    </div>
                    <div class="widget-content">
                        <div class="table-responsive">
                            <table data-sortable class="table">
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>广告名</th>
                                    <th>图片</th>
                                    <th>操作</th>
                                </tr>
                                {volist name='list' key='key' id='v'}
                                <tr>
                                    <td>{$v.poster_id}</td>
                                    <td >{$v.poster_name}</td>
                                    <td><img style="width: 110px;" src="/static/posterpic/{$v.poster_pic}"></td>
                                    <td>
                                        <a href="{:url('admin/poster/edit', ['id'=>$v['poster_id']])}" class="btn btn-primary">修改</a>
                                        <button  data-id='{$v.poster_id}'  class="btn btn-danger delArt" >删除</button>
                                    </td>
                                </tr>
                                {/volist}
                                </thead>
                                <tbody>
                                </tbody>
                            </table>
                            {$list->render()}
                        </div>
                    </div>
                </div>
            </div>
        </div>




        <!-- Footer Start -->
        <footer>
            Huban Creative &copy; 2014
            <div class="footer-links pull-right">
                <a href="#">About</a><a href="#">Support</a><a href="#">Terms of Service</a><a href="#">Legal</a><a
                    href="#">Help</a><a href="#">Contact Us</a>
            </div>
        </footer>
        <!-- Footer End -->
    </div>
    <!-- ============================================================== -->
    <!-- End content here -->
    <!-- ============================================================== -->

</div>

<script type="text/javascript">


    $(function () {
            // 触发删除用户
            $('.delArt').click(function () {
                var id = $(this).attr('data-id');
                    // alert(dataid);

                if (confirm('您确定要 [ 删 除 ] 该广告吗?')) {
                    var obj = $(this).parents('tr');

                    var info = 'posterid'+'='+id;
                    // alert(info);
                    $.ajax({
                        type: 'post',
                        url: '/admin/poster/delete',
                        data: info,
                        dataType : 'json',
                        success : function (data){

                            if (data.status) {
                                toastr.success('删除成功');
                                obj.remove();
                            } else {
                                toastr.error('删除失败');
                            }
                            // alert(data.status);
                        },
                        error : function () {
                            alert('执行失败');
                        }
                    });
                }
        });
    })

    toastr.options = {
    closeButton: true,// 是否显示关闭按钮
    progressBar: true,// 实现显示计时条
    timeOut: "2000",// 自动关闭时间
    positionClass: "toast-top-right"// 提示位置
    // positionClass: "toast-top-full-width"// 提示位置
    // toast-top-full-width 顶端，宽度铺满整个屏幕
    // toast-top-right  顶端右边
    };

</script>
{/block}